package com.example.idachuappone.index.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.example.idachuappone.R;
import com.example.idachuappone.cook.entity.CookResult;
import com.example.idachuappone.cook.entity.Recipe;
import com.example.idachuappone.cook.entity.Tags;
import com.example.idachuappone.utils.BitmapUtilHelper;
import com.example.idachuappone.utils.Utils;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.bitmap.BitmapDisplayConfig;
import com.lidroid.xutils.bitmap.callback.BitmapLoadCallBack;
import com.lidroid.xutils.bitmap.callback.BitmapLoadFrom;
import java.util.List;

public class CookAdapterList extends BaseAdapter {
    private String breed;
    private BitmapUtils bu;
    private Context context;
    ViewHolder holder;
    private List<CookResult> list;

    private class ViewHolder {
        ImageView img_cook;
        ImageView img_green;
        ImageView img_star;
        TextView tv_bespeak_num;
        TextView tv_breed;
        TextView tv_green_name;
        TextView tv_name;

        private ViewHolder() {
        }
    }

    public void setBreed(String breed) {
        this.breed = breed;
    }

    public CookAdapterList(Context context, BitmapUtils bu) {
        this.holder = null;
        this.context = context;
        this.bu = bu;
    }

    public void setList(List<CookResult> list) {
        this.list = list;
    }

    public int getCount() {
        return this.list == null ? 0 : this.list.size();
    }

    public Object getItem(int position) {
        return this.list == null ? null : (CookResult) this.list.get(position);
    }

    public long getItemId(int position) {
        return (long) position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LinearLayout.inflate(this.context, R.layout.simple_index_item_list, null);
            this.holder = new ViewHolder();
            this.holder.img_cook = (ImageView) convertView.findViewById(R.id.img_cook);
            this.holder.img_green = (ImageView) convertView.findViewById(R.id.img_green);
            this.holder.img_star = (ImageView) convertView.findViewById(R.id.img_star);
            this.holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            this.holder.tv_breed = (TextView) convertView.findViewById(R.id.tv_breed);
            this.holder.tv_green_name = (TextView) convertView.findViewById(R.id.tv_green_name);
            this.holder.tv_bespeak_num = (TextView) convertView.findViewById(R.id.tv_bespeak_num);
            convertView.setTag(this.holder);
        } else {
            this.holder = (ViewHolder) convertView.getTag();
        }
        CookResult cookResult = (CookResult) this.list.get(position);
        this.holder.tv_name.setText(cookResult.getName());
        if (this.breed != null && this.breed.trim().length() > 0) {
            this.holder.tv_breed.setText("\u64c5\u957f" + this.breed);
        } else if (cookResult.getTags() == null || cookResult.getTags().size() <= 0) {
            this.holder.tv_breed.setText("\u64c5\u957f\u5bb6\u5e38\u83dc");
        } else {
            this.holder.tv_breed.setText("\u64c5\u957f" + ((Tags) cookResult.getTags().get(0)).getName());
        }
        this.holder.tv_bespeak_num.setText(cookResult.getBespeak_num());
        this.bu.display(this.holder.img_green, ((Recipe) cookResult.getRecipe().get(0)).getImg_small());
        this.holder.tv_green_name.setText(((Recipe) cookResult.getRecipe().get(0)).getName());
        this.bu.display(this.holder.img_cook, cookResult.getHead_small(), new BitmapLoadCallBack<View>() {
            public void onLoadCompleted(View view, String arg1, Bitmap bitmap, BitmapDisplayConfig arg3, BitmapLoadFrom arg4) {
                ((ImageView) view).setImageBitmap(BitmapUtilHelper.getCroppedRoundBitmap(bitmap, Utils.dip2px(CookAdapterList.this.context, 20.0f)));
            }

            public void onLoadFailed(View arg0, String arg1, Drawable arg2) {
            }
        });
        if (Double.valueOf(cookResult.getStar()).doubleValue() > 4.0d) {
            this.holder.img_star.setBackgroundResource(R.drawable.icon_star05);
        } else if (Double.valueOf(cookResult.getStar()).doubleValue() > 3.0d) {
            this.holder.img_star.setBackgroundResource(R.drawable.icon_star04);
        } else if (Double.valueOf(cookResult.getStar()).doubleValue() > 2.0d) {
            this.holder.img_star.setBackgroundResource(R.drawable.icon_star03);
        } else if (Double.valueOf(cookResult.getStar()).doubleValue() > 1.0d) {
            this.holder.img_star.setBackgroundResource(R.drawable.icon_star02);
        } else {
            this.holder.img_star.setBackgroundResource(R.drawable.icon_star01);
        }
        return convertView;
    }
}
